package com.yix.sso.study.cookie.dao.impl;

import com.yix.sso.study.cookie.dao.LoginDao;
import com.yix.sso.study.cookie.entity.UserInfo;
import com.yix.sso.study.cookie.mapper.UserRowMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LoginDaoJdbc implements LoginDao {
    private static UserRowMapper userRowMapper = new UserRowMapper();
    @Autowired
    private JdbcTemplate jdbcTemplate;


    @Override
    public UserInfo getUserInfoByAccount(String name) {
        final String sql = " select * from user where  name = ? ";
        final List<UserInfo> list = this.jdbcTemplate.query(sql, new Object[]{name}, userRowMapper);

        UserInfo user = null;
        if (!list.isEmpty()) {
            user = list.get(0);
        }

        return user;

    }
}
